import request from '@/utils/request'
import { Pagination } from '@/types/global';

// 字典类型数据
export interface DictTypeData {
    id?: number;
    name?: string;
    type?: string;
    status?: number;
}

// 查询参数
export interface DictTypeParams extends Partial<DictTypeData> {
    current?: number;
    size?: number;
    startDate?: string;
    endDate?: string;
}

// 字典类型列表
export function pageDictType(params: DictTypeParams) {
    return request<Pagination<DictTypeData[]>>('get', '/dict/type/page', {params})
}

// 新增字典类型
export function saveDictType(data: DictTypeData) {
    return request('post', '/dict/type', data)
}

// 修改字典类型
export function updateDictType(data: DictTypeData) {
    return request('put', '/dict/type', data)
}

// 修改字典类型状态
export function updateDictTypeStatus(data: DictTypeData) {
    return request('put', '/dict/type/status', data)
}

// 刷新字典类型
export function refreshDictType() {
    return request('put', '/dict/type/cache/refresh')
}

// 删除字典类型
export function deleteDictType(ids: any) {
    return request('delete', '/dict/type/' + ids)
}

// 字典数据
export interface DictData {
    id?: number;
    label?: string;
    value?: string;
    dictType?: string;
    cssClass?: string;
    listClass?: string;
    isDefault?: number;
    sort?: number;
    status?: number;
    remark?: string;
}

// 字典查询参数
export interface DictParams extends Partial<DictData> {
    current?: number;
    size?: number;
    startDate?: string;
    endDate?: string;
}

// 获取字典列表
export function pageDict(params: DictParams) {
    return request<Pagination<DictData>>('get', '/dict/page', {params})
}

// 添加字典
export function saveDict(data: DictData) {
    return request('post', '/dict', data)
}

// 修改字典
export function updateDict(data: DictData) {
    return request('put', '/dict', data)
}

// 修改字典状态
export function updateDictStatus(data: DictData) {
    return request('put', '/dict/status', data)
}

// 删除字典
export function deleteDict(ids: any) {
    return request('delete', '/dict/' + ids)
}